<?php
include("../../include/connexion.php");

function query_resultat_consult_service($nom, $prenom, $service, $poste){
	$req_resultat = "Select idemp as ID,
			NOMEMP AS nom,
			PRENOMEMP AS prenom,
			DATENAISSANCE AS datenaiss,
			nomservice as service,
			nomposte as poste 
			from employe as E left join service as S on E.idservice=S.idservice
			left join poste as P on E.idposte=P.idposte";
		
	$cpt =0;
	 if( $nom != ""){
		if ($cpt == 0){
		$req_resultat .= " where nomEmp = \"$nom\"";
		$cpt++;
		}
		else 
		$req_resultat .= " AND nomEmp = \"$nom\"";
	}
	if ($prenom != ""){
		if ($cpt == 0){
		$req_resultat .= " where prenomEmp = \"$prenom\"";
		$cpt++;
		}
		else 
		$req_resultat .= " AND prenomEmp = \"$prenom\"";
	}
	if( strcmp($service, 'Tous') != 0){
		if ($cpt == 0){
		$req_resultat .= " where idservice = \"$service\"";
		$cpt++;
		}
		else 
		$req_resultat .= " AND idservice =\"$service\"";
	}
	if( strcmp($poste, 'Tous') != 0){
		if ($cpt == 0){
		$req_resultat .= " where nomposte = \"$poste\"";
		$cpt++;
		}
		else 
		$req_resultat .= " AND nomposte = \"$poste\"";
		}
		
		$req_resultat .= " order by nomemp;";

	$rep_resultat = mysql_query($req_resultat);
	$tab_employ;
	$i = 0;
	while ($employe = mysql_fetch_array($rep_resultat)){
		$tab_employ[$i]['ID'] = $employe['ID'];
		$tab_employ[$i]['nom'] = $employe['nom'];
		$tab_employ[$i]['prenom'] = $employe['prenom'];
		$tab_employ[$i]['datenaiss'] = $employe['datenaiss'];
		$tab_employ[$i]['service'] = $employe['service'];
		$tab_employ[$i]['poste'] = $employe['poste'];
			$i++;
	}
	if(isset($tab_employ)) {
		return $tab_employ;
	}

	
}

function query_poste_CS($idServ){
$req_poste = " SELECT distinct nomposte
			   from employe as E left join service as S on E.idservice=S.idservice
		       left join poste as P on E.idposte=P.idposte
               where E.idservice = \"$idServ\"";
$res_poste = mysql_query($req_poste);


$i=0;
$tab_poste;
while ($poste = mysql_fetch_array($res_poste)){
	$tab_poste[$i] = $poste['nomposte'];
	$i++;	
}	
return $tab_poste;

}

				 
?>